package com.shigen.demo.base;

import java.util.HashMap;
import java.util.Objects;
import lombok.Data;
import lombok.ToString;

/**
 * equalsAndHashCode
 *
 * @author shigenfu
 * @date 2022/5/13 10:11 下午
 */
public class EqualsAndHashCode {
  @Data
  @ToString
  static class User {
    private String name;

    public User(String name) {
      this.name = name;
    }

    // @Override
    // public boolean equals(Object obj) {
    //   User user = (User) obj;
    //   return user.getName().equals(this.name);
    // }

    @Override
    public int hashCode() {
      return Objects.hash(name);
    }
  }

  public static void main(String[] args) {
    HashMap<User, String> map = new HashMap<>();
    map.put(new User("shigen"), "shigen");

    System.out.println(map.get(new User("shigen")));
  }


}
